<template>
  <!-- 岗位等级 -->
  <view>
    <u-line color="#EEEEF5" class="line" />
    <view class="styleJobDescriptionContainer">
      <view class="styleJobDescriptionTitle"> {{ layerInfo.title }}</view>
      <view class="content" v-if="layerInfo.data && layerInfo.data.length > 0">
        <!-- 知识雷达图 -->
        <RadarChart
          :canvasId="canvasId"
          :chartData="radarData"
          :indicator="radarIndicator"
          :legendData="legendData"
          :areaColor="['#54d57f', '#3698ff', '#a76aff', '#fe88d3']"
        ></RadarChart>
        <!-- 阶段分析 -->
        <view class="bottom-title">
          {{ analyzeTitle }}
        </view>
        <view class="bottom">
          <view class="content">
            <view
              class="myIntroduction"
              @click="changeHeight('introduction')"
              >{{ showMajorIntroduction }}</view
            >
            <view class="glass" v-if="!textareaHeight"></view>

            <view
              v-if="
                showMajorIntroduction && showMajorIntroduction != '暂无数据'
              "
              :class="[textareaHeight ? 'avatar-rotate' : 'avatar']"
              @click="changeHeight('introduction')"
            >
            </view>
          </view>
        </view>
      </view>
      <Empty
        v-else
        :baseImg="emptyImg"
        :text="emptyTitle"
        :fontWeight="400"
        textColor="#bfbfbf"
        class="empty"
        spacing="0"
      />
    </view>
  </view>
</template>
<script>
import Empty from '@/components/Empty.vue';
import LoginDialog from '@/components/LoginDialog';
import RadarChart from './charts/RadarChart';

export default {
  components: {
    RadarChart,
    Empty,
    LoginDialog
  },
  props: {
    layerInfo: {
      type: Object,
      default: function () {
        return {};
      }
    },
    canvasId: {
      type: String,
      default: 'radarChart'
    }
  },
  data() {
    return {
      loading: false,
      radarData: [], //雷达图
      radarIndicator: [], //雷达图指标
      legendData: [], //雷达图图例
      chartData: {}, //雷达图数据
      emptyTitle: '暂无数据',
      textareaHeight: true, // true表示隐藏  false表示全部展示
      isIOS: uni.getSystemInfoSync().platform == 'ios',
      analyzeTitle: '阶段知识分析', //阶段分析标题
      showMajorIntroduction: '', //展示的字符（50个）
      majorIntroduction: '' //展示的字符（全部）
    };
  },
  mounted() {
    this.handleLayerInfo();
  },
  created() {
    this.isIOS = uni.getSystemInfoSync().platform == 'ios';
  },
  watch: {
    layerInfo: {
      handler(val) {
        if (val.data && val.data.length > 0) {
          this.$nextTick(() => {
            this.handleLayerInfo();
          });
        }
      },
      deep: true
    }
  },
  methods: {
    changeHeight(type) {
      if (type == 'introduction') {
        if (this.textareaHeight) {
          if (this.majorIntroduction.length > 50) {
            this.showMajorIntroduction = this.majorIntroduction.substring(
              0,
              50
            );
          } else {
            this.showMajorIntroduction = this.majorIntroduction;
          }
        } else {
          this.showMajorIntroduction = this.majorIntroduction;
        }
        this.textareaHeight = !this.textareaHeight;
      }
    },
    handleLayerInfo() {
      const jsonList = this.layerInfo.data;

      jsonList.forEach((item, index) => {
        if (index == 0) {
          //雷达图数据
          const tempData = JSON.parse(item.layerValue);
          this.legendData = Object.keys(tempData);
          this.radarIndicator = this.getIndicator(tempData);
          this.radarData = this.getRadarData(tempData);
        }
        if (index == 1) {
          //文字解读
          //阶段分析
          this.analyzeTitle = item.layerKey;
          this.majorIntroduction = item.layerValue;
        }
      });
      this.changeHeight('introduction');
    },
    getIndicator(val) {
      let arr = [];
      Object.keys(val[this.legendData[0]]).forEach((key) => {
        arr.push({
          name: key,
          max: 5
        });
      });
      return arr;
    },
    getRadarData(val) {
      let arr = [];
      this.legendData.forEach((item) => {
        let obj = {};
        obj.name = item;
        obj.value = Object.values(val[item]);
        arr.push(obj);
      });
      return arr;
    }
  }
};
</script>
<style lang="scss" scoped>
$img-base-person: $img-base + 'career/';
.line {
  width: calc(100% - 40rpx);
  margin: 64rpx 20rpx;
}
.styleJobDescriptionContainer {
  background-color: white;
  border-radius: 16rpx;
  width: calc(100% - 40rpx);
  margin: 0 20rpx;
  .styleJobDescriptionTitle {
    color: #222222;
    font-size: 30rpx;
    font-weight: 800;
  }
  .content {
    width: 100%;
    border-radius: 8rpx;
    .radar-content {
      display: flex;
      justify-content: center;
      .radar-content-item {
        display: flex;
        align-items: center;
        margin: 24rpx 14rpx;
        .radar-title-value {
          width: 16rpx;
          height: 16rpx;
          border-radius: 8rpx;
        }
        .radar-title-name {
          margin-left: 6rpx;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 24rpx;
          color: #8193b2;
          line-height: 28rpx;
          text-align: left;
          font-style: normal;
        }
      }
    }
    .bottom-title {
      margin-top: 30rpx;
      font-family: PingFang-SC, PingFang-SC;
      font-weight: bold;
      font-size: 30rpx;
      color: #000000;
      line-height: 21px;
      text-align: left;
      font-style: normal;
    }
    .bottom {
      padding: 16rpx 0 24rpx 0;
      .content {
        font-family: D-DIN-PRO, D-DIN-PRO;
        font-weight: bold;
        font-size: 30rpx;
        color: #000000;
        margin-bottom: 36rpx;
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        justify-content: flex-start;
        position: relative;
        margin: 0px;
        .avatar {
          position: absolute;
          top: 45%;
          right: 0;
          width: 32rpx;
          height: 32rpx;
          background-image: url($img-base-person + 'positionDictionary/downArrowInBasicInfo.png');
          background-size: 100%;

          img {
            width: 32rpx;
            height: 32rpx;
          }
        }

        .avatar-rotate {
          position: absolute;
          top: 90%;
          right: 0;
          width: 32rpx;
          height: 32rpx;
          transform: rotate(180deg);
          background-image: url($img-base-person + 'positionDictionary/downArrowInBasicInfo.png');
          background-size: 100%;

          img {
            width: 32rpx;
            height: 32rpx;
          }
        }

        span-ios {
          width: 150rpx;
          margin-top: 19rpx;
        }

        span-android {
          width: 150rpx;
          margin-top: 5rpx;
        }

        .introduction {
          width: 630rpx;
          overflow: hidden;
          font-weight: 400;
          font-size: 28rpx;
          color: #666666;
          line-height: 40rpx;
          font-family: D-DIN-PRO, D-DIN-PRO;
          padding: 0;
        }

        .myIntroduction {
          width: 630rpx;
          white-space: pre-wrap;
          font-weight: 400;
          font-size: 28rpx;
          color: #666666;
          line-height: 40rpx;
          font-family: D-DIN-PRO, D-DIN-PRO;
        }

        .glass {
          width: 20rpx;
          height: 100%;
          position: absolute;
          right: 32rpx;
          background: linear-gradient(
            180deg,
            rgba(255, 255, 255, 0) 0%,
            #ffffff 100%
          );
        }
        .u-input__textarea {
          padding: 0 !important;
        }
      }
    }
  }
}
</style>
